//
// Created by 86152 on 2021/7/30.
//

#ifndef DATASTRUCTURE_PART5_H
#define DATASTRUCTURE_PART5_H

namespace Part5{
    void getNext(int* next, char* pattern, int len){
        next[0] = -1;
        next[1] = 0;
        int i = 1;
        int j = 0;
        while (i < len-1){
            if (j == -1 || pattern[i] == pattern[j]){
                i++;j++;
                if (pattern[i] != j)next[i] = j;
                else next[i] = next[j];
            }else{
                j = next[j];
            }
        }
    }
}

#endif //DATASTRUCTURE_PART5_H
